using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace Microsoft.Phone.Controls.Primitives
{
	[TemplatePart(Name = "CenteringTransform", Type = typeof(TranslateTransform)), TemplatePart(Name = "ItemsPanel", Type = typeof(Panel)), TemplatePart(Name = "PanningTransform", Type = typeof(TranslateTransform))]
	public class LoopingSelector : Control
	{
		private enum State
		{
			Normal,
			Expanded,
			Dragging,
			Snapping,
			Flicking
		}
		private const string ItemsPanelName = "ItemsPanel";
		private const string CenteringTransformName = "CenteringTransform";
		private const string PanningTransformName = "PanningTransform";
		private const double DragSensitivity = 12.0;
		private static readonly Duration _selectDuration = new Duration(TimeSpan.FromMilliseconds(500.0));
		private readonly IEasingFunction _selectEase;
		private static readonly Duration _panDuration = new Duration(TimeSpan.FromMilliseconds(100.0));
		private readonly IEasingFunction _panEase;
		private DoubleAnimation _panelAnimation;
		private Storyboard _panelStoryboard;
		private Panel _itemsPanel;
		private TranslateTransform _panningTransform;
		private TranslateTransform _centeringTransform;
		private bool _isSelecting;
		private LoopingSelectorItem _selectedItem;
		private Queue<LoopingSelectorItem> _temporaryItemsPool;
		private double _minimumPanelScroll;
		private double _maximumPanelScroll;
		private int _additionalItemsCount;
		private bool _isAnimating;
		private double _dragTarget;
		private bool _isAllowedToDragVertically;
		private bool _isDragging;
		private LoopingSelector.State _state;
		public static readonly DependencyProperty DataSourceProperty = DependencyProperty.Register("DataSource", typeof(ILoopingSelectorDataSource), typeof(LoopingSelector), new PropertyMetadata(null, new PropertyChangedCallback(LoopingSelector.OnDataModelChanged)));
		public static readonly DependencyProperty ItemTemplateProperty = DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(LoopingSelector), new PropertyMetadata(null));
		public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register("IsExpanded", typeof(bool), typeof(LoopingSelector), new PropertyMetadata(false, new PropertyChangedCallback(LoopingSelector.OnIsExpandedChanged)));
		public event DependencyPropertyChangedEventHandler IsExpandedChanged;
		public ILoopingSelectorDataSource DataSource
		{
			get
			{
				return (ILoopingSelectorDataSource)base.GetValue(LoopingSelector.DataSourceProperty);
			}
			set
			{
				if (this.DataSource != null)
				{
					this.DataSource.SelectionChanged -= new EventHandler<SelectionChangedEventArgs>(this.value_SelectionChanged);
				}
				base.SetValue(LoopingSelector.DataSourceProperty, value);
				if (value != null)
				{
					value.SelectionChanged += new EventHandler<SelectionChangedEventArgs>(this.value_SelectionChanged);
				}
			}
		}
		public DataTemplate ItemTemplate
		{
			get
			{
				return (DataTemplate)base.GetValue(LoopingSelector.ItemTemplateProperty);
			}
			set
			{
				base.SetValue(LoopingSelector.ItemTemplateProperty, value);
			}
		}
		public Size ItemSize
		{
			get;
			set;
		}
		public Thickness ItemMargin
		{
			get;
			set;
		}
		public bool IsExpanded
		{
			get
			{
				return (bool)base.GetValue(LoopingSelector.IsExpandedProperty);
			}
			set
			{
				base.SetValue(LoopingSelector.IsExpandedProperty, value);
			}
		}
		private bool IsReady
		{
			get
			{
				return base.get_ActualHeight() > 0.0 && this.DataSource != null && this._itemsPanel != null;
			}
		}
		private double ActualItemWidth
		{
			get
			{
				return base.get_Padding().get_Left() + base.get_Padding().get_Right() + this.ItemSize.get_Width();
			}
		}
		private double ActualItemHeight
		{
			get
			{
				return base.get_Padding().get_Top() + base.get_Padding().get_Bottom() + this.ItemSize.get_Height();
			}
		}
		private void value_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (!this.IsReady)
			{
				return;
			}
			if (!this._isSelecting && e.get_AddedItems().get_Count() == 1)
			{
				object obj = e.get_AddedItems().get_Item(0);
				using (IEnumerator<UIElement> enumerator = this._itemsPanel.get_Children().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						LoopingSelectorItem loopingSelectorItem = (LoopingSelectorItem)enumerator.get_Current();
						if (loopingSelectorItem.get_DataContext() == obj)
						{
							this.SelectAndSnapTo(loopingSelectorItem);
							return;
						}
					}
				}
				this.UpdateData();
			}
		}
		private static void OnDataModelChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			LoopingSelector loopingSelector = (LoopingSelector)obj;
			loopingSelector.UpdateData();
		}
		private void DataModel_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (!this.IsReady)
			{
				return;
			}
			if (!this._isSelecting && e.get_AddedItems().get_Count() == 1)
			{
				object obj = e.get_AddedItems().get_Item(0);
				using (IEnumerator<UIElement> enumerator = this._itemsPanel.get_Children().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						LoopingSelectorItem loopingSelectorItem = (LoopingSelectorItem)enumerator.get_Current();
						if (loopingSelectorItem.get_DataContext() == obj)
						{
							this.SelectAndSnapTo(loopingSelectorItem);
							break;
						}
					}
				}
				this.UpdateData();
			}
		}
		public LoopingSelector()
		{
			ExponentialEase exponentialEase = new ExponentialEase();
			exponentialEase.set_EasingMode(2);
			this._selectEase = exponentialEase;
			this._panEase = new ExponentialEase();
			this._minimumPanelScroll = -3.4028234663852886E+38;
			this._maximumPanelScroll = 3.4028234663852886E+38;
			this._isAllowedToDragVertically = true;
			base..ctor();
			base.set_DefaultStyleKey(typeof(LoopingSelector));
			this.CreateEventHandlers();
		}
		private static void OnIsExpandedChanged(object sender, DependencyPropertyChangedEventArgs e)
		{
			LoopingSelector loopingSelector = (LoopingSelector)sender;
			loopingSelector.UpdateItemState();
			if (!loopingSelector.IsExpanded)
			{
				loopingSelector.SelectAndSnapToClosest();
			}
			if (loopingSelector._state == LoopingSelector.State.Normal || loopingSelector._state == LoopingSelector.State.Expanded)
			{
				loopingSelector._state = (loopingSelector.IsExpanded ? LoopingSelector.State.Expanded : LoopingSelector.State.Normal);
			}
			DependencyPropertyChangedEventHandler isExpandedChanged = loopingSelector.IsExpandedChanged;
			if (isExpandedChanged != null)
			{
				isExpandedChanged.Invoke(loopingSelector, e);
			}
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this._itemsPanel = ((base.GetTemplateChild("ItemsPanel") as Panel) ?? new Canvas());
			this._centeringTransform = ((base.GetTemplateChild("CenteringTransform") as TranslateTransform) ?? new TranslateTransform());
			this._panningTransform = ((base.GetTemplateChild("PanningTransform") as TranslateTransform) ?? new TranslateTransform());
			this.CreateVisuals();
		}
		private void LoopingSelector_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			if (this._isAnimating)
			{
				double y = this._panningTransform.get_Y();
				this.StopAnimation();
				this._panningTransform.set_Y(y);
				this._isAnimating = false;
				this._state = LoopingSelector.State.Dragging;
			}
		}
		private void LoopingSelector_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
		{
			if (this._selectedItem != sender && this._state == LoopingSelector.State.Dragging && !this._isAnimating)
			{
				this.SelectAndSnapToClosest();
				this._state = LoopingSelector.State.Expanded;
			}
		}
		private void OnTap(object sender, GestureEventArgs e)
		{
			if (this._panningTransform != null)
			{
				this.SelectAndSnapToClosest();
				e.set_Handled(true);
			}
		}
		private void OnManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			this._isAllowedToDragVertically = true;
			this._isDragging = false;
		}
		private void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
		{
			if (this._isDragging)
			{
				this.AnimatePanel(LoopingSelector._panDuration, this._panEase, this._dragTarget += e.get_DeltaManipulation().get_Translation().get_Y());
				e.set_Handled(true);
				return;
			}
			if (Math.Abs(e.get_CumulativeManipulation().get_Translation().get_X()) > 12.0)
			{
				this._isAllowedToDragVertically = false;
				return;
			}
			if (this._isAllowedToDragVertically && Math.Abs(e.get_CumulativeManipulation().get_Translation().get_Y()) > 12.0)
			{
				this._isDragging = true;
				this._state = LoopingSelector.State.Dragging;
				e.set_Handled(true);
				this._selectedItem = null;
				if (!this.IsExpanded)
				{
					this.IsExpanded = true;
				}
				this._dragTarget = this._panningTransform.get_Y();
				this.UpdateItemState();
			}
		}
		private void OnManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			if (this._isDragging)
			{
				if (e.get_IsInertial())
				{
					this._state = LoopingSelector.State.Flicking;
					this._selectedItem = null;
					if (!this.IsExpanded)
					{
						this.IsExpanded = true;
					}
					Point initialVelocity = new Point(0.0, e.get_FinalVelocities().get_LinearVelocity().get_Y());
					double stopTime = PhysicsConstants.GetStopTime(initialVelocity);
					Point stopPoint = PhysicsConstants.GetStopPoint(initialVelocity);
					IEasingFunction easingFunction = PhysicsConstants.GetEasingFunction(stopTime);
					this.AnimatePanel(new Duration(TimeSpan.FromSeconds(stopTime)), easingFunction, this._panningTransform.get_Y() + stopPoint.get_Y());
					e.set_Handled(true);
					this._selectedItem = null;
					this.UpdateItemState();
				}
				if (this._state == LoopingSelector.State.Dragging)
				{
					this.SelectAndSnapToClosest();
				}
				this._state = LoopingSelector.State.Expanded;
			}
		}
		private void OnSizeChanged(object sender, SizeChangedEventArgs e)
		{
			this._centeringTransform.set_Y(Math.Round(e.get_NewSize().get_Height() / 2.0));
			RectangleGeometry rectangleGeometry = new RectangleGeometry();
			rectangleGeometry.set_Rect(new Rect(0.0, 0.0, e.get_NewSize().get_Width(), e.get_NewSize().get_Height()));
			base.set_Clip(rectangleGeometry);
			this.UpdateData();
		}
		private void OnWrapperClick(object sender, EventArgs e)
		{
			if (this._state == LoopingSelector.State.Normal)
			{
				this._state = LoopingSelector.State.Expanded;
				this.IsExpanded = true;
				return;
			}
			if (this._state == LoopingSelector.State.Expanded)
			{
				if (!this._isAnimating && sender == this._selectedItem)
				{
					this._state = LoopingSelector.State.Normal;
					this.IsExpanded = false;
					return;
				}
				if (sender != this._selectedItem && !this._isAnimating)
				{
					this.SelectAndSnapTo((LoopingSelectorItem)sender);
				}
			}
		}
		private void SelectAndSnapTo(LoopingSelectorItem item)
		{
			if (item == null)
			{
				return;
			}
			if (this._selectedItem != null)
			{
				this._selectedItem.SetState(this.IsExpanded ? LoopingSelectorItem.State.Expanded : LoopingSelectorItem.State.Normal, true);
			}
			if (this._selectedItem != item)
			{
				this._selectedItem = item;
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this._isSelecting = true;
					this.DataSource.SelectedItem = item.get_DataContext();
					this._isSelecting = false;
				});
			}
			this._selectedItem.SetState(LoopingSelectorItem.State.Selected, true);
			TranslateTransform transform = item.Transform;
			if (transform != null)
			{
				double num = -transform.get_Y() - Math.Round(item.get_ActualHeight() / 2.0);
				if (this._panningTransform.get_Y() != num)
				{
					this.AnimatePanel(LoopingSelector._selectDuration, this._selectEase, num);
				}
			}
		}
		private void UpdateData()
		{
			if (!this.IsReady)
			{
				return;
			}
			this._temporaryItemsPool = new Queue<LoopingSelectorItem>(this._itemsPanel.get_Children().get_Count());
			using (IEnumerator<UIElement> enumerator = this._itemsPanel.get_Children().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					LoopingSelectorItem loopingSelectorItem = (LoopingSelectorItem)enumerator.get_Current();
					if (loopingSelectorItem.GetState() == LoopingSelectorItem.State.Selected)
					{
						loopingSelectorItem.SetState(LoopingSelectorItem.State.Normal, false);
					}
					this._temporaryItemsPool.Enqueue(loopingSelectorItem);
					loopingSelectorItem.Remove();
				}
			}
			this._itemsPanel.get_Children().Clear();
			this.StopAnimation();
			this._panningTransform.set_Y(0.0);
			this._minimumPanelScroll = -3.4028234663852886E+38;
			this._maximumPanelScroll = 3.4028234663852886E+38;
			this.Balance();
		}
		private void AnimatePanel(Duration duration, IEasingFunction ease, double to)
		{
			double num = Math.Max(this._minimumPanelScroll, Math.Min(this._maximumPanelScroll, to));
			if (to != num)
			{
				double num2 = Math.Abs(this._panningTransform.get_Y() - to);
				double num3 = Math.Abs(this._panningTransform.get_Y() - num);
				double num4 = num3 / num2;
				duration = new Duration(TimeSpan.FromMilliseconds((double)duration.get_TimeSpan().get_Milliseconds() * num4));
				to = num;
			}
			double y = this._panningTransform.get_Y();
			this.StopAnimation();
			CompositionTarget.add_Rendering(new EventHandler(this.AnimationPerFrameCallback));
			this._panelAnimation.set_Duration(duration);
			this._panelAnimation.set_EasingFunction(ease);
			this._panelAnimation.set_From(new double?(y));
			this._panelAnimation.set_To(new double?(to));
			this._panelStoryboard.Begin();
			this._panelStoryboard.SeekAlignedToLastTick(TimeSpan.Zero);
			this._isAnimating = true;
		}
		private void StopAnimation()
		{
			this._panelStoryboard.Stop();
			CompositionTarget.remove_Rendering(new EventHandler(this.AnimationPerFrameCallback));
		}
		private void Brake(double newStoppingPoint)
		{
			double num = this._panelAnimation.get_To().get_Value() - this._panelAnimation.get_From().get_Value();
			double num2 = newStoppingPoint - this._panningTransform.get_Y();
			double num3 = num2 / num;
			Duration duration = new Duration(TimeSpan.FromMilliseconds((double)this._panelAnimation.get_Duration().get_TimeSpan().get_Milliseconds() * num3));
			this.AnimatePanel(duration, this._panelAnimation.get_EasingFunction(), newStoppingPoint);
		}
		private void Balance()
		{
			if (!this.IsReady)
			{
				return;
			}
			double actualItemWidth = this.ActualItemWidth;
			double actualItemHeight = this.ActualItemHeight;
			this._additionalItemsCount = (int)Math.Round(base.get_ActualHeight() * 1.5 / actualItemHeight);
			LoopingSelectorItem loopingSelectorItem;
			if (this._itemsPanel.get_Children().get_Count() == 0)
			{
				loopingSelectorItem = (this._selectedItem = this.CreateAndAddItem(this._itemsPanel, this.DataSource.SelectedItem));
				loopingSelectorItem.Transform.set_Y(-actualItemHeight / 2.0);
				loopingSelectorItem.Transform.set_X((base.get_ActualWidth() - actualItemWidth) / 2.0);
				loopingSelectorItem.SetState(LoopingSelectorItem.State.Selected, false);
			}
			else
			{
				int closestItem = this.GetClosestItem();
				loopingSelectorItem = (LoopingSelectorItem)this._itemsPanel.get_Children().get_Item(closestItem);
			}
			int i;
			LoopingSelectorItem loopingSelectorItem2 = LoopingSelector.GetFirstItem(loopingSelectorItem, out i);
			int j;
			LoopingSelectorItem loopingSelectorItem3 = LoopingSelector.GetLastItem(loopingSelectorItem, out j);
			if (i >= j)
			{
				if (i >= this._additionalItemsCount)
				{
					goto IL_203;
				}
			}
			while (i < this._additionalItemsCount)
			{
				object previous = this.DataSource.GetPrevious(loopingSelectorItem2.get_DataContext());
				if (previous != null)
				{
					LoopingSelectorItem loopingSelectorItem4;
					if (j > this._additionalItemsCount)
					{
						loopingSelectorItem4 = loopingSelectorItem3;
						loopingSelectorItem3 = loopingSelectorItem3.Previous;
						loopingSelectorItem4.Remove();
						ContentControl arg_143_0 = loopingSelectorItem4;
						object content;
						loopingSelectorItem4.set_DataContext(content = previous);
						arg_143_0.set_Content(content);
					}
					else
					{
						loopingSelectorItem4 = this.CreateAndAddItem(this._itemsPanel, previous);
						loopingSelectorItem4.Transform.set_X((base.get_ActualWidth() - actualItemWidth) / 2.0);
					}
					loopingSelectorItem4.Transform.set_Y(loopingSelectorItem2.Transform.get_Y() - actualItemHeight);
					loopingSelectorItem4.InsertBefore(loopingSelectorItem2);
					loopingSelectorItem2 = loopingSelectorItem4;
					i++;
				}
				else
				{
					this._maximumPanelScroll = -loopingSelectorItem2.Transform.get_Y() - actualItemHeight / 2.0;
					if (this._isAnimating && this._panelAnimation.get_To().get_Value() > this._maximumPanelScroll)
					{
						this.Brake(this._maximumPanelScroll);
						break;
					}
					break;
				}
			}
			IL_203:
			if (j >= i)
			{
				if (j >= this._additionalItemsCount)
				{
					goto IL_32A;
				}
			}
			while (j < this._additionalItemsCount)
			{
				object next = this.DataSource.GetNext(loopingSelectorItem3.get_DataContext());
				if (next != null)
				{
					LoopingSelectorItem loopingSelectorItem5;
					if (i > this._additionalItemsCount)
					{
						loopingSelectorItem5 = loopingSelectorItem2;
						loopingSelectorItem2 = loopingSelectorItem2.Next;
						loopingSelectorItem5.Remove();
						ContentControl arg_26A_0 = loopingSelectorItem5;
						object content2;
						loopingSelectorItem5.set_DataContext(content2 = next);
						arg_26A_0.set_Content(content2);
					}
					else
					{
						loopingSelectorItem5 = this.CreateAndAddItem(this._itemsPanel, next);
						loopingSelectorItem5.Transform.set_X((base.get_ActualWidth() - actualItemWidth) / 2.0);
					}
					loopingSelectorItem5.Transform.set_Y(loopingSelectorItem3.Transform.get_Y() + actualItemHeight);
					loopingSelectorItem5.InsertAfter(loopingSelectorItem3);
					loopingSelectorItem3 = loopingSelectorItem5;
					j++;
				}
				else
				{
					this._minimumPanelScroll = -loopingSelectorItem3.Transform.get_Y() - actualItemHeight / 2.0;
					if (this._isAnimating && this._panelAnimation.get_To().get_Value() < this._minimumPanelScroll)
					{
						this.Brake(this._minimumPanelScroll);
						break;
					}
					break;
				}
			}
			IL_32A:
			this._temporaryItemsPool = null;
		}
		private static LoopingSelectorItem GetFirstItem(LoopingSelectorItem item, out int count)
		{
			count = 0;
			while (item.Previous != null)
			{
				count++;
				item = item.Previous;
			}
			return item;
		}
		private static LoopingSelectorItem GetLastItem(LoopingSelectorItem item, out int count)
		{
			count = 0;
			while (item.Next != null)
			{
				count++;
				item = item.Next;
			}
			return item;
		}
		private void AnimationPerFrameCallback(object sender, EventArgs e)
		{
			this.Balance();
		}
		private int GetClosestItem()
		{
			if (!this.IsReady)
			{
				return -1;
			}
			double actualItemHeight = this.ActualItemHeight;
			int count = this._itemsPanel.get_Children().get_Count();
			double y = this._panningTransform.get_Y();
			double num = actualItemHeight / 2.0;
			int result = -1;
			double num2 = 1.7976931348623157E+308;
			for (int i = 0; i < count; i++)
			{
				LoopingSelectorItem loopingSelectorItem = (LoopingSelectorItem)this._itemsPanel.get_Children().get_Item(i);
				double num3 = Math.Abs(loopingSelectorItem.Transform.get_Y() + num + y);
				if (num3 <= num)
				{
					result = i;
					return result;
				}
				if (num2 > num3)
				{
					num2 = num3;
					result = i;
				}
			}
			return result;
		}
		private void PanelStoryboardCompleted(object sender, EventArgs e)
		{
			CompositionTarget.remove_Rendering(new EventHandler(this.AnimationPerFrameCallback));
			this._isAnimating = false;
			if (this._state != LoopingSelector.State.Dragging)
			{
				this.SelectAndSnapToClosest();
			}
		}
		private void SelectAndSnapToClosest()
		{
			if (!this.IsReady)
			{
				return;
			}
			int closestItem = this.GetClosestItem();
			if (closestItem == -1)
			{
				return;
			}
			LoopingSelectorItem item = (LoopingSelectorItem)this._itemsPanel.get_Children().get_Item(closestItem);
			this.SelectAndSnapTo(item);
		}
		private void UpdateItemState()
		{
			if (!this.IsReady)
			{
				return;
			}
			bool isExpanded = this.IsExpanded;
			using (IEnumerator<UIElement> enumerator = this._itemsPanel.get_Children().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					LoopingSelectorItem loopingSelectorItem = (LoopingSelectorItem)enumerator.get_Current();
					if (loopingSelectorItem == this._selectedItem)
					{
						loopingSelectorItem.SetState(LoopingSelectorItem.State.Selected, true);
					}
					else
					{
						loopingSelectorItem.SetState(isExpanded ? LoopingSelectorItem.State.Expanded : LoopingSelectorItem.State.Normal, true);
					}
				}
			}
		}
		private void CreateVisuals()
		{
			this._panelAnimation = new DoubleAnimation();
			Storyboard.SetTarget(this._panelAnimation, this._panningTransform);
			Storyboard.SetTargetProperty(this._panelAnimation, new PropertyPath("Y", new object[0]));
			this._panelStoryboard = new Storyboard();
			this._panelStoryboard.get_Children().Add(this._panelAnimation);
			this._panelStoryboard.add_Completed(new EventHandler(this.PanelStoryboardCompleted));
		}
		private void CreateEventHandlers()
		{
			base.add_SizeChanged(new SizeChangedEventHandler(this.OnSizeChanged));
			base.add_ManipulationStarted(new EventHandler<ManipulationStartedEventArgs>(this.OnManipulationStarted));
			base.add_ManipulationCompleted(new EventHandler<ManipulationCompletedEventArgs>(this.OnManipulationCompleted));
			base.add_ManipulationDelta(new EventHandler<ManipulationDeltaEventArgs>(this.OnManipulationDelta));
			base.add_Tap(new EventHandler<GestureEventArgs>(this.OnTap));
			base.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(this.LoopingSelector_MouseLeftButtonDown), true);
			base.AddHandler(UIElement.MouseLeftButtonUpEvent, new MouseButtonEventHandler(this.LoopingSelector_MouseLeftButtonUp), true);
		}
		private LoopingSelectorItem CreateAndAddItem(Panel parent, object content)
		{
			bool flag;
			LoopingSelectorItem loopingSelectorItem = (flag = (this._temporaryItemsPool != null && this._temporaryItemsPool.get_Count() > 0)) ? this._temporaryItemsPool.Dequeue() : new LoopingSelectorItem();
			if (!flag)
			{
				loopingSelectorItem.set_ContentTemplate(this.ItemTemplate);
				loopingSelectorItem.set_Width(this.ItemSize.get_Width());
				loopingSelectorItem.set_Height(this.ItemSize.get_Height());
				loopingSelectorItem.set_Padding(this.ItemMargin);
				loopingSelectorItem.Click += new EventHandler<EventArgs>(this.OnWrapperClick);
			}
			FrameworkElement arg_92_0 = loopingSelectorItem;
			loopingSelectorItem.set_Content(content);
			arg_92_0.set_DataContext(content);
			parent.get_Children().Add(loopingSelectorItem);
			if (!flag)
			{
				loopingSelectorItem.ApplyTemplate();
			}
			return loopingSelectorItem;
		}
	}
}
